package com.thread.sync.sync09;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


class RunTest implements Runnable {
    @Override
    public void run() {
        System.out.println("run");
    }
}

public class ScheculedTest {
    public static void main(String[] args) {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(10);
        //可实现任务定时,但实际业务中一般都用spring的定时器,这个技术比较老了
        //pool.schedule(new RunTest(), 2, TimeUnit.SECONDS);//2秒后执行此任务
        //可实现任务的轮询,指定时间间隔循环执行此任务     任务    延迟时间(即2秒后开始执行)   间隔多少秒之后再执行(一直循环)
        pool.scheduleAtFixedRate(new RunTest(), 2, 2, TimeUnit.SECONDS);
        pool.scheduleWithFixedDelay(new RunTest(), 2, 2, TimeUnit.SECONDS);
    }
}
